<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>DLC Search Engine: src/main/java/DataAccess/postgresql/PostgreSQLDocumentDAO.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">DLC Search Engine
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/main/java/DataAccess/postgresql/PostgreSQLDocumentDAO.java</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_postgre_s_q_l_document_d_a_o_8java.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="namespacedataaccess_1_1postgresql.html">00001</a> <span class="keyword">package </span>dataaccess.postgresql;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> com.utn.searchengine.Document;
<a name="l00004"></a>00004 <span class="keyword">import</span> dataaccess.dao.DocumentDAO;
<a name="l00005"></a>00005 <span class="keyword">import</span> dataaccess.dbmanager.PostgreDBManager;
<a name="l00006"></a>00006 <span class="keyword">import</span> java.sql.Connection;
<a name="l00007"></a>00007 <span class="keyword">import</span> java.sql.PreparedStatement;
<a name="l00008"></a>00008 <span class="keyword">import</span> java.sql.ResultSet;
<a name="l00009"></a>00009 <span class="keyword">import</span> java.sql.SQLException;
<a name="l00010"></a>00010 
<a name="l00015"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html">00015</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html">PostgreSQLDocumentDAO</a> <span class="keyword">implements</span> <a class="code" href="interfacedataaccess_1_1dao_1_1_document_d_a_o.html">DocumentDAO</a> {
<a name="l00016"></a>00016 
<a name="l00023"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#acaaa543e7323f3e2a575c77f5c665064">00023</a>     <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#acaaa543e7323f3e2a575c77f5c665064">grabarWebSite</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00024"></a>00024         PreparedStatement st;
<a name="l00025"></a>00025         Connection con;
<a name="l00026"></a>00026         <span class="keywordflow">try</span> {
<a name="l00027"></a>00027             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00028"></a>00028             <span class="keyword">synchronized</span> (con) {
<a name="l00029"></a>00029                 String query = <span class="stringliteral">&quot;SELECT fn_save_page(?,?);&quot;</span>;
<a name="l00030"></a>00030                 st = con.prepareStatement(query);
<a name="l00031"></a>00031                 st.setString(1, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00032"></a>00032                 st.setDouble(2, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a2b03754624147f5f1a9ea50c549e9606">getModule</a>());
<a name="l00033"></a>00033                 st.executeQuery();
<a name="l00034"></a>00034                 st.close();
<a name="l00035"></a>00035                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00036"></a>00036             }
<a name="l00037"></a>00037         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00038"></a>00038             System.out.println(<span class="stringliteral">&quot;sqlexcep&quot;</span> + ex.toString());
<a name="l00039"></a>00039             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00040"></a>00040         }
<a name="l00041"></a>00041     }
<a name="l00042"></a>00042     <span class="comment">/*</span>
<a name="l00043"></a>00043 <span class="comment">     * obtiene la cantidad total de documento</span>
<a name="l00044"></a>00044 <span class="comment">     */</span>
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#aff57f39a2beb558bbd14fe73c92447d5">00046</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#aff57f39a2beb558bbd14fe73c92447d5">obtenerCantidadDocument</a>() {
<a name="l00047"></a>00047         <span class="keywordtype">int</span> cant;
<a name="l00048"></a>00048         PreparedStatement st;
<a name="l00049"></a>00049         Connection con;
<a name="l00050"></a>00050         <span class="keywordflow">try</span> {
<a name="l00051"></a>00051             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00052"></a>00052             <span class="keyword">synchronized</span> (con) {
<a name="l00053"></a>00053                 String query = <span class="stringliteral">&quot;SELECT COUNT(*) FROM Page p;&quot;</span>;
<a name="l00054"></a>00054                 st = con.prepareStatement(query);
<a name="l00055"></a>00055                 ResultSet results = st.executeQuery();
<a name="l00056"></a>00056                 results.next();
<a name="l00057"></a>00057                 cant = results.getInt(1);
<a name="l00058"></a>00058                 st.close();
<a name="l00059"></a>00059 
<a name="l00060"></a>00060             }
<a name="l00061"></a>00061         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00062"></a>00062             System.out.println(<span class="stringliteral">&quot;&quot;</span> + ex.toString());
<a name="l00063"></a>00063             cant = -1;
<a name="l00064"></a>00064         }
<a name="l00065"></a>00065 
<a name="l00066"></a>00066         <span class="keywordflow">return</span> cant;
<a name="l00067"></a>00067 
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069 
<a name="l00077"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#a8129984712142f8220304815ff2c2a19">00077</a>     <span class="keyword">public</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_document_d_a_o.html#a8129984712142f8220304815ff2c2a19">obtenerDocument</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> website) {
<a name="l00078"></a>00078         <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> ret = null;
<a name="l00079"></a>00079         PreparedStatement st;
<a name="l00080"></a>00080         Connection con;
<a name="l00081"></a>00081         <span class="keywordflow">try</span> {
<a name="l00082"></a>00082             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00083"></a>00083             String query = <span class="stringliteral">&quot;select id_Url ,url_Name,Modulo from Page where url_Name = ?&quot;</span>;
<a name="l00084"></a>00084             st = con.prepareStatement(query);
<a name="l00085"></a>00085             st.setString(1, website.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00086"></a>00086             ResultSet results = st.executeQuery();
<a name="l00087"></a>00087             <span class="keywordflow">if</span> (results.next()) {
<a name="l00088"></a>00088                 ret = <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a>(results.getString(<span class="stringliteral">&quot;url_Name&quot;</span>), <span class="stringliteral">&quot;&quot;</span>);
<a name="l00089"></a>00089                 ret.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#ad8a50ff977b6138ae86a199a1f987459">setModule</a>(results.getDouble(<span class="stringliteral">&quot;Modulo&quot;</span>));
<a name="l00090"></a>00090             }
<a name="l00091"></a>00091             results.close();
<a name="l00092"></a>00092             st.close();
<a name="l00093"></a>00093 
<a name="l00094"></a>00094         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00095"></a>00095         }
<a name="l00096"></a>00096         <span class="keywordflow">return</span> ret;
<a name="l00097"></a>00097     }
<a name="l00098"></a>00098 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Feb 16 2012 02:45:40 for DLC Search Engine by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
